home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Technology Seed / Mac Tech Seed Feb '97.toast / ODF Release 3 / ODFDev / Draw / Sources / DrawPart.cpp < prev    next >
Encoding:
Text File  |  1996-12-16  |  40.6 KB  |  1,381 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                DrawPart.cpp
  4. //    Release Version:    $ ODF 3 $
  5. //
  6. //    Author:                Henri Lamiraux
  7. //
  8. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #include "ODFDraw.hpp"
  13.  
  14. #ifndef DRAWPART_H
  15. #include "DrawPart.h"
  16. #endif
  17.  
  18. #ifndef DEFINES_K
  19. #include "Defines.k"
  20. #endif
  21.  
  22. #ifndef BINDING_K
  23. #include "Binding.k"
  24. #endif
  25.  
  26. #ifndef CONSTANT_H
  27. #include "Constant.h"
  28. #endif
  29.  
  30. #ifndef DRAWCONT_H
  31. #include "DrawCont.h"
  32. #endif
  33.  
  34. #ifndef DRAWFRM_H
  35. #include "DrawFrm.h"
  36. #endif
  37.  
  38. #ifndef DRAWPRXY_H
  39. #include "DrawPrxy.h"
  40. #endif
  41.  
  42. #ifndef DIALOG_H
  43. #include "Dialog.h"
  44. #endif
  45.  
  46. #ifndef BASESHP_H
  47. #include "BaseShp.h"
  48. #endif
  49.  
  50. #ifndef BOUNDSHP_H
  51. #include "BoundShp.h"
  52. #endif
  53.  
  54. #ifndef LINESHP_H
  55. #include "LineShp.h"
  56. #endif
  57.  
  58. #ifndef OVALSHP_H
  59. #include "OvalShp.h"
  60. #endif
  61.  
  62. #ifndef RECTSHP_H
  63. #include "RectShp.h"
  64. #endif
  65.  
  66. #ifndef RRECTSHP_H
  67. #include "RRectShp.h"
  68. #endif
  69.  
  70. #ifndef TEXTSHP_H
  71. #include "TextShp.h"
  72. #endif
  73.  
  74. #ifndef DRAWSEL_H
  75. #include "DrawSel.h"
  76. #endif
  77.  
  78. #ifndef DRAWLINK_H
  79. #include "DrawLink.h"
  80. #endif
  81.  
  82. #ifndef TOOLFRM_H
  83. #include "ToolFrm.h"
  84. #endif
  85.  
  86. #ifndef PALFRAME_H
  87. #include "PalFrame.h"
  88. #endif
  89.  
  90. #ifndef PATFRAME_H
  91. #include "PatFrame.h"
  92. #endif
  93.  
  94. #ifndef DRAWCMDS_H
  95. #include "DrawCmds.h"
  96. #endif
  97.  
  98. #ifndef DRAWCLIP_H
  99. #include "DrawClip.h"
  100. #endif
  101.  
  102. #ifndef PRINTHDL_H
  103. #include "PrintHdl.h"
  104. #endif
  105.  
  106. #ifndef GROUPCMD_H
  107. #include "GroupCmd.h"
  108. #endif
  109.  
  110. #ifndef RULER_H
  111. #include "Ruler.h"
  112. #endif
  113.  
  114. #ifndef SOM_ODFExamples_ODFDrawEmbeddedFramesIterator_xh
  115. #include "SOMIter.xh"
  116. #endif
  117.  
  118. // ----- Framework Layer -----
  119.  
  120. #ifndef FWABOUT_H
  121. #include "FWAbout.h"
  122. #endif
  123.  
  124. #ifndef FWSUUTIL_H
  125. #include "FWSUUtil.h"
  126. #endif
  127.  
  128. #ifndef FWPXYITE_H
  129. #include "FWPxyIte.h"
  130. #endif
  131.  
  132. #ifndef FWUTIL_H
  133. #include "FWUtil.h"
  134. #endif
  135.  
  136. #ifndef FWSCLBAR_H
  137. #include "FWSclBar.h"
  138. #endif
  139.  
  140. #ifndef FWPRESEN_H
  141. #include "FWPresen.h"
  142. #endif
  143.  
  144. // ----- OS Layer -----
  145.  
  146. #ifndef FWAPLEVT_H
  147. #include "FWAplEvt.h"
  148. #endif
  149.  
  150. #ifndef FWCOLORP_H
  151. #include "FWColorP.h"
  152. #endif
  153.  
  154. #ifndef FWRECT_H
  155. #include "FWRect.h"
  156. #endif
  157.  
  158. #ifndef FWRECSHP_H
  159. #include "FWRecShp.h"
  160. #endif
  161.  
  162. #ifndef FWWINDOW_H
  163. #include "FWWindow.h"
  164. #endif
  165.  
  166. #ifndef FWFLOWIN_H
  167. #include "FWFloWin.h"
  168. #endif
  169.  
  170. #ifndef FWEVENT_H
  171. #include "FWEvent.h"
  172. #endif
  173.  
  174. #ifndef FWMENU_H
  175. #include "FWMenu.h"
  176. #endif
  177.  
  178. #ifndef FWODGEOM_H
  179. #include "FWODGeom.h"
  180. #endif
  181.  
  182. #ifndef FWALERT_H
  183. #include "FWAlert.h"
  184. #endif
  185.  
  186. #ifndef FWCFMRES_H
  187. #include "FWCFMRes.h"
  188. #endif
  189.  
  190. #ifndef SLMixOS_H
  191. #include "SLMixOS.h"
  192. #endif
  193.  
  194. // ----- Foundation Includes -----
  195.  
  196. #ifndef FWSTREAM_H
  197. #include "FWStream.h"
  198. #endif
  199.  
  200. #ifndef FWSTRING_H
  201. #include "FWString.h"
  202. #endif
  203.  
  204. #ifndef FWSUSINK_H
  205. #include "FWSUSink.h"
  206. #endif
  207.  
  208. // ----- OpenDoc Includes -----
  209.  
  210. #ifndef SOM_ODArbitrator_xh
  211. #include <Arbitrat.xh>
  212. #endif
  213.  
  214. #ifndef SOM_ODDispatcher_xh
  215. #include <Disptch.xh>
  216. #endif
  217.  
  218. #ifndef SOM_ODShape_xh
  219. #include <Shape.xh>
  220. #endif
  221.  
  222. #ifndef SOM_ODStorageUnit_xh
  223. #include <StorageU.xh>
  224. #endif
  225.  
  226. #ifndef SOM_ODSession_xh
  227. #include <ODSessn.xh>
  228. #endif
  229.  
  230. #ifndef SOM_Module_OpenDoc_StdProps_defined
  231. #include <StdProps.xh>
  232. #endif
  233.  
  234. #ifndef SOM_ODInfo_xh
  235. #include <Info.xh>
  236. #endif
  237.  
  238. #ifndef FWARCSHP_H
  239. #include "FWArcShp.h"
  240. #endif
  241.  
  242. #ifndef FWPRINFO_H
  243. #include "FWPrInfo.h"
  244. #endif
  245.  
  246. #ifndef FWITERS_H
  247. #include "FWIters.h"
  248. #endif
  249.  
  250. //========================================================================================
  251. // Runtime Information
  252. //========================================================================================
  253.  
  254. #ifdef FW_BUILD_MAC
  255. #pragma segment odfdraw
  256. #endif
  257.  
  258. FW_DEFINE_CLASS_M2(CDrawPart, FW_CEmbeddingPart, FW_MEmbeddingPartScriptable)
  259. FW_DEFINE_AUTO(CDrawPart)
  260.  
  261. //========================================================================================
  262. //    class CDrawPart
  263. //========================================================================================
  264.  
  265. //----------------------------------------------------------------------------------------
  266. //    CDrawPart::CDrawPart
  267. //----------------------------------------------------------------------------------------
  268.  
  269. CDrawPart::CDrawPart(ODPart* odPart) :
  270.     FW_CEmbeddingPart(odPart, FW_gInstance, kPartInfoID),
  271.     FW_MEmbeddingPartScriptable(),
  272.     FW_MReceiver(),
  273.     fNbEmbedded(0),
  274.     fHorizPages(1),
  275.     fVertPages(1),
  276.     fPageSize(FW_IntToFixed(kDrawingSizeX), FW_IntToFixed(kDrawingSizeY)),
  277.     fPartContent(NULL),
  278.     fCurrentPenSize(FW_kFixedPos1),
  279.     fRenderVerb(kFillFrame),
  280.     fPaletteWindow(NULL),
  281.     fPatternWindow(NULL),
  282.     fToolsWindow(NULL),
  283.     fToolFrame(NULL),
  284.     fPaletteFrame(NULL),
  285.     fPatternFrame(NULL),
  286.     fPalettePresentation(NULL),
  287.     fPatternPresentation(NULL),
  288.     fToolPresentation(NULL),
  289.     fMainPresentation(NULL),
  290.     fAlignObjectsPresentation(NULL),    
  291.     fTool(kSelectTool),    
  292.     fFillColor(FW_kRGBWhite),
  293.     fFrameColor(FW_kRGBBlack),
  294.     fAutoGrid(TRUE),
  295.     fUnit(cInchUnit),
  296.     fArcUnit(cDegreesUnit),
  297.     fPostCreated(FALSE),
  298.     fHasMenuFocus(false),
  299.     fEditMenuID(0),
  300.     fEditMenuPosition(0),
  301.     fRoundRectRadius(FW_IntToFixed(32)),
  302.     fRoundEnds(FALSE)
  303. {
  304.     
  305.     FW_END_CONSTRUCTOR
  306. }
  307.  
  308. //----------------------------------------------------------------------------------------
  309. //    CDrawPart::~CDrawPart
  310. //----------------------------------------------------------------------------------------
  311.  
  312. CDrawPart::~CDrawPart()
  313. {
  314.     FW_START_DESTRUCTOR
  315. }
  316.  
  317. //----------------------------------------------------------------------------------------
  318. //    CDrawPart::ReleaseAll
  319. //----------------------------------------------------------------------------------------
  320.  
  321. void CDrawPart::ReleaseAll(Environment *ev)
  322. {
  323.     if (fHasMenuFocus)
  324.         UninstallCustomEditMenu(ev);
  325.  
  326.     FW_CEmbeddingPart::ReleaseAll(ev);
  327.     
  328.     delete fPaletteWindow;
  329.     delete fPatternWindow;
  330.     delete fToolsWindow;
  331. }
  332.  
  333. //----------------------------------------------------------------------------------------
  334. //    CDrawPart::Initialize
  335. //----------------------------------------------------------------------------------------
  336.  
  337. void CDrawPart::Initialize(Environment *ev, ODStorageUnit* storageUnit, FW_Boolean fromStorage)
  338. {
  339.     // ----- Call Inherited Initialize -----
  340.     FW_CEmbeddingPart::Initialize(ev, storageUnit, fromStorage);
  341.  
  342.     fDrawingSize.Set(FW_IntToFixed(kDrawingSizeX), FW_IntToFixed(kDrawingSizeY));
  343.  
  344. #ifdef FW_BUILD_WIN
  345.     // [HLX] Temporary embed menu for windows
  346.     WinAddEmbedMenu(ev, GetMenuBar(ev));
  347. #endif
  348.  
  349.     // ----- We are using FW_CToggleItem and FW_CSubMenuItem so avoid dead stripping -----
  350.     FW_DO_NOT_DEAD_STRIP(FW_CToggleItem);
  351.     FW_DO_NOT_DEAD_STRIP(FW_CSubMenuItem);
  352.  
  353.     // ----- Tokenize -----
  354.     fDrawSelection = FW_NEW(CDrawSelection, (ev, this));    // Attention I don't own the selection the presentation will
  355.     
  356.     fToolPresentation             = RegisterPresentation(ev, kToolPresentation, FALSE);
  357.     fPalettePresentation         = RegisterPresentation(ev, kPalettePresentation, FALSE);
  358.     fPatternPresentation         = RegisterPresentation(ev, kPatternPresentation, FALSE);
  359.     fMainPresentation             = RegisterPresentation(ev, kMainPresentation, TRUE, kDrawViewNotRoot, kDrawView, fDrawSelection);
  360.     fPrintPresentation            = RegisterPresentation(ev, kPrintPresentation, FALSE, kDrawViewPrinting, kDrawViewPrinting);
  361.     fRoundCornersPresentation    = RegisterPresentation(ev, kRoundCornersPresentation, FALSE, kRoundCornersDialog, kRoundCornersDialog);
  362.     fAlignObjectsPresentation     = RegisterPresentation(ev, kAlignObjectsPresentation, FALSE);
  363.     
  364.     InitializePalettes(ev);
  365.  
  366.     // ----- Pattern Table -----
  367.     fPatternTable[0]     = FW_kBlackPat;
  368.     fPatternTable[1]     = FW_kWhitePat;
  369.     fPatternTable[2]     = FW_kGrayPat;
  370.     fPatternTable[3]     = FW_kLightGrayPat;
  371.     fPatternTable[4]     = FW_kDarkGrayPat;
  372.     fPatternTable[5]     = FW_kHorizontalPat;
  373.     fPatternTable[6]     = FW_kVerticalPat;
  374.     fPatternTable[7]     = FW_kFDiagonalPat;
  375.     fPatternTable[8]     = FW_kBDiagonalPat;
  376.     fPatternTable[9]     = FW_kCrossPat;
  377.     fPatternTable[10]     = FW_kDiagCrossPat;
  378.     fPatternTable[11]     = FW_kAntPat;
  379.     
  380.     fFillPatIndex = 0;
  381.     fFramePatIndex = 0;
  382.     
  383.     // ----- Register PICT type -----
  384.     RegisterKind(ev, 'PICT', kODPlatformDataType, FW_kDataInterchangeStorage, FW_kExportEnabled);
  385. }
  386.  
  387. //------------------------------------------------------------------------------
  388. //    CDrawPart::SetDrawingSize
  389. //------------------------------------------------------------------------------
  390.  
  391. void CDrawPart::SetDrawingSize(Environment* ev, const FW_CPoint& newSize)
  392. {
  393.     if(fDrawingSize != newSize)
  394.     {
  395.         fDrawingSize = newSize;
  396.  
  397.         FW_CPresentationFrameIterator ite(ev, fMainPresentation);
  398.         for (CDrawFrame* theFrame = (CDrawFrame*) ite.First(ev); ite.IsNotComplete(ev); theFrame = (CDrawFrame*) ite.Next(ev))
  399.         {
  400.             theFrame->AdjustContentViewSize(ev, FW_kInvalidate);
  401.  
  402.             CRuler* horzRuler = (CRuler*) theFrame->FindViewByID(ev, kHorzRulerID);
  403.             CRuler* vertRuler = (CRuler*) theFrame->FindViewByID(ev, kVertRulerID);
  404.             
  405.             FW_CPoint extent;
  406.  
  407.             extent = horzRuler->GetExtent(ev);
  408.             extent.x = newSize.x;
  409.             horzRuler->SetExtent(ev, extent);
  410.  
  411.             extent = vertRuler->GetExtent(ev);
  412.             extent.y = newSize.y;
  413.             vertRuler->SetExtent(ev, extent);
  414.  
  415.             theFrame->GetContentView(ev)->SetExtent(ev, fDrawingSize);
  416.             
  417.             theFrame->Invalidate(ev);
  418.         }    
  419.     }
  420. }
  421.  
  422. //------------------------------------------------------------------------------
  423. //    CDrawPart::InitializePalettes
  424. //------------------------------------------------------------------------------
  425.  
  426. void CDrawPart::InitializePalettes(Environment *ev)
  427. {
  428.     FW_CPoint position(FW_IntToFixed(100), FW_IntToFixed(100));
  429.     fPatternWindow = new FW_CFloatingWindow(ev, 
  430.                                             this, 
  431.                                             fPatternPresentation, 
  432.                                             FW_CString(""), 
  433.                                             FW_kZeroPoint, 
  434.                                             position,
  435.                                             TRUE,
  436.                                             FALSE);        // resizeable
  437.  
  438.     fPaletteWindow = new FW_CFloatingWindow(ev, 
  439.                                             this,
  440.                                             fPalettePresentation, 
  441.                                             FW_CString(""), 
  442.                                             FW_kZeroPoint, 
  443.                                             position,
  444.                                             TRUE,
  445.                                             FALSE);        // resizeable
  446.  
  447.     FW_CRect screenBounds;
  448.     ::FW_GetMainScreenBounds(screenBounds);
  449.     screenBounds.Inset(FW_IntToFixed(3), FW_IntToFixed(3));
  450.  
  451.     FW_CPoint windowSize(FW_IntToFixed(kToolsWindowWidth), FW_IntToFixed(kToolsWindowHeight));
  452.     fToolsWindow = new FW_CFloatingWindow(ev, 
  453.                                             this, 
  454.                                             fToolPresentation, 
  455.                                             FW_CString(""), 
  456.                                             windowSize, 
  457.                                             screenBounds.TopLeft(),
  458.                                             TRUE,
  459.                                             FALSE);        // resizeable
  460. }
  461.  
  462. //----------------------------------------------------------------------------------------
  463. //    CDrawPart::NewDocumentWindow
  464. //----------------------------------------------------------------------------------------
  465.  
  466. FW_CWindow* CDrawPart::NewDocumentWindow(Environment* ev)
  467. {
  468.     FW_CPoint sbSize = FW_CScrollBar::GetDefaultScrollBarSize();
  469.  
  470.     // ----- Add the rulers -----
  471.     sbSize.x += kRulerWidth;
  472.     sbSize.y += kRulerWidth;
  473.     
  474.     FW_CPoint drawingSize(fDrawingSize.x + sbSize.x, fDrawingSize.y + sbSize.y);
  475.         
  476.     FW_CRect screenBounds;
  477.     ::FW_GetMainScreenBounds(screenBounds);
  478.     screenBounds.Inset(FW_IntToFixed(3), FW_IntToFixed(3));
  479.     
  480.     // Make room for the tool palettes
  481.     screenBounds.left += FW_IntToFixed(3 + kToolsWindowWidth + 3);
  482.     
  483.     return new FW_CWindow(ev,
  484.                         this,
  485.                          FW_CPart::fgViewAsFrameToken,
  486.                         fMainPresentation,
  487.                         drawingSize,
  488.                         screenBounds.TopLeft(),
  489.                         FW_kDocumentWindow);
  490. }
  491.  
  492. //---------------------------------------------------------------------------------------
  493. //    FW_CPart::InternalizeContent
  494. //---------------------------------------------------------------------------------------
  495. //    I override FW_CPart::InternalizeContent because I want to read my annotations
  496.  
  497. FW_Boolean CDrawPart::InternalizeContent(Environment* ev, ODStorageUnit* storageUnit, FW_CCloneInfo* cloneInfo)
  498. {
  499.     FW_Boolean result = FW_CEmbeddingPart::InternalizeContent(ev, storageUnit, cloneInfo);
  500.     
  501.     // ----- Read general information -----
  502.     if (result && storageUnit->Exists(ev, kContentAnnotationProp, (ODValueType)kContentAnnotationValue, 0))
  503.     {
  504.         FW_PStorageUnitSink suSink(ev, storageUnit, kContentAnnotationProp, kContentAnnotationValue);
  505.         FW_PBufferedSink sink(ev, suSink);
  506.         FW_CReadableStream stream(sink);
  507.         stream >> fCurrentPenSize;
  508.         stream >> fRenderVerb;
  509.         stream >> fAutoGrid;
  510.         stream >> fHorizPages;
  511.         stream >> fVertPages;
  512.         stream >> fPageSize;
  513.         stream >> fRoundRectRadius;
  514.         stream >> fRoundEnds;
  515.     }
  516.         
  517.     return result;
  518. }
  519.  
  520. //---------------------------------------------------------------------------------------
  521. //    FW_CPart::ExternalizeContent
  522. //---------------------------------------------------------------------------------------
  523. //    I override FW_CPart::ExternalizeContent because I want to write my annotations
  524.  
  525. void CDrawPart::ExternalizeContent(Environment* ev, ODStorageUnit* storageUnit, FW_CCloneInfo* cloneInfo)
  526. {
  527.     FW_CEmbeddingPart::ExternalizeContent(ev, storageUnit, cloneInfo);
  528.     
  529.     // ----- Write general information -----
  530.     //    FW_SUAddPropValue correctly test if the property and value exist before
  531.     //    trying to create them
  532.     FW_SUAddPropValue(ev, storageUnit, kContentAnnotationProp, kContentAnnotationValue);
  533.  
  534.     FW_PStorageUnitSink suSink(ev, storageUnit, kContentAnnotationProp, kContentAnnotationValue);
  535.     FW_CWritableStream stream(suSink);
  536.     stream << fCurrentPenSize;
  537.     stream << fRenderVerb;
  538.     stream << fAutoGrid;
  539.     stream << fHorizPages;
  540.     stream << fVertPages;
  541.     stream << fPageSize;
  542.     stream << fRoundRectRadius;
  543.     stream << fRoundEnds;
  544. }
  545.  
  546. //----------------------------------------------------------------------------------------
  547. //    CDrawPart::SetDocumentDimensions
  548. //----------------------------------------------------------------------------------------
  549.  
  550. void CDrawPart::SetDocumentDimensions(Environment *ev, unsigned char hPages, unsigned char vPages)
  551. {
  552. FW_UNUSED(ev);
  553.     fHorizPages = hPages;
  554.     fVertPages = vPages;
  555. }
  556.  
  557. //----------------------------------------------------------------------------------------
  558. //    CDrawPart::GetDocumentDimensions
  559. //----------------------------------------------------------------------------------------
  560.  
  561. void CDrawPart::GetDocumentDimensions(Environment *ev, unsigned char& hPages, unsigned char& vPages)
  562. {
  563. FW_UNUSED(ev);
  564.     hPages = fHorizPages;
  565.     vPages = fVertPages;
  566. }
  567.  
  568.  
  569. //---------------------------------------------------------------------------------------
  570. //    CDrawPart::PrintInfoChanged
  571. //---------------------------------------------------------------------------------------
  572.  
  573. void CDrawPart::PrintInfoChanged(Environment *ev, FW_CPrintInfo* printInfo)
  574. {
  575.     FW_ASSERT(printInfo != NULL);
  576.     
  577.     FW_CRect pageRect = printInfo->GetPageBounds();
  578.     
  579.     // convert the printable extent to content coordinates (72dpi)
  580.     fPageSize = printInfo->PageToContent(FW_CPoint(pageRect.Width(), pageRect.Height()));
  581.  
  582.     unsigned char hPages, vPages;
  583.     GetDocumentDimensions(ev, hPages, vPages);
  584.     SetDrawingSize(ev, FW_CPoint(FW_MultipliedByInt(fPageSize.x, hPages), FW_MultipliedByInt(fPageSize.y, vPages)));
  585. }
  586.  
  587. //----------------------------------------------------------------------------------------
  588. //    CDrawPart::NewPartContent
  589. //----------------------------------------------------------------------------------------
  590.  
  591. FW_CContent* CDrawPart::NewPartContent(Environment* ev)
  592. {
  593.     fPartContent = FW_NEW(CDrawPartContent, (ev, this));
  594.     return fPartContent;
  595. }
  596.  
  597. //----------------------------------------------------------------------------------------
  598. //    CDrawPart::NewLinkManager
  599. //----------------------------------------------------------------------------------------
  600. FW_CLinkManager* CDrawPart::NewLinkManager(Environment *ev)
  601. {
  602.     CDrawLinkManager* linkMgr = FW_NEW(CDrawLinkManager, (ev, this));
  603.     return linkMgr;
  604. }
  605.  
  606. //----------------------------------------------------------------------------------------
  607. //    CDrawPart::AddShapeToPart
  608. //----------------------------------------------------------------------------------------
  609.  
  610. void CDrawPart::AddShapeToPart(Environment* ev, CBaseShape* shape)
  611. {
  612.     fPartContent->AddShape(ev, shape);
  613. }
  614.  
  615. //----------------------------------------------------------------------------------------
  616. //    CDrawPart::RemoveShapeFromPart
  617. //----------------------------------------------------------------------------------------
  618.  
  619. void CDrawPart::RemoveShapeFromPart(Environment* ev, CBaseShape* shape)
  620. {
  621.     fPartContent->RemoveShape(ev, shape);
  622.     shape->Removed(ev);
  623. }
  624.  
  625. //----------------------------------------------------------------------------------------
  626. //    CDrawPart::DoAbout
  627. //----------------------------------------------------------------------------------------
  628.  
  629. FW_Handled CDrawPart::DoAbout(Environment* ev)
  630. {
  631.     ::FW_About(ev, this, kAbout);
  632.     
  633.     return FW_kHandled;
  634. }
  635.  
  636. //----------------------------------------------------------------------------------------
  637. //    CDrawPart::DoMenu
  638. //----------------------------------------------------------------------------------------
  639.  
  640. FW_Handled CDrawPart::DoMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent)
  641. {
  642.     FW_CString name("ODFDraw");
  643.     FW_CString sorry("Sorry, not yet implemented!");
  644.  
  645.     FW_Handled result = FW_kHandled;
  646.     ODCommandID commandID = theMenuEvent.GetCommandID(ev);
  647.     
  648.     if (cPen1 <= commandID && commandID <= cPen5)
  649.     {
  650.         int temp = cPen1;
  651.         FW_Fixed penSize = FW_IntToFixed(commandID - temp + 1);
  652.         if (!fDrawSelection->IsEmpty(ev))
  653.         {
  654.             CChangePenSizeCommand* cmd = FW_NEW(CChangePenSizeCommand, (ev, this, this->GetLastActiveFrame(ev), fDrawSelection, penSize));
  655.             cmd->Execute(ev);
  656.         }
  657.         else
  658.             fCurrentPenSize = penSize;
  659.     }
  660.     else
  661.     {
  662.         switch (commandID)
  663.         {
  664.             case cHideShowPattern:
  665.                 fPatternWindow->ShowHide(ev, !fPatternWindow->IsShown(ev));
  666.                 break;
  667.                 
  668.             case cHideShowPalette:
  669.                 fPaletteWindow->ShowHide(ev, !fPaletteWindow->IsShown(ev));
  670.                 break;
  671.             
  672.             case cHideShowTools:
  673.                 fToolsWindow->ShowHide(ev, !fToolsWindow->IsShown(ev));
  674.                 break;
  675.  
  676.             case cMoveForward:
  677.                 if (fPartContent->MoveForward())
  678.                 {
  679.                     UpdateAfterMove(ev);
  680.                     this->Changed(ev);
  681.                 }
  682.                 break;
  683.             case cMoveToFront:
  684.                 fPartContent->MoveToFront();
  685.                 UpdateAfterMove(ev);
  686.                 this->Changed(ev);
  687.                 break;
  688.             case cMoveBackward:
  689.                 if (fPartContent->MoveBackward())
  690.                 {
  691.                     UpdateAfterMove(ev);
  692.                     this->Changed(ev);
  693.                 }
  694.                 break;
  695.             case cMoveToBack:
  696.                 fPartContent->MoveToBack();
  697.                 UpdateAfterMove(ev);
  698.                 this->Changed(ev);
  699.                 break;
  700.             
  701.             case cAutoGrid:
  702.                 fAutoGrid = !fAutoGrid;
  703.                 break;
  704.  
  705.             case cGroup:
  706.               {
  707.                 CGroupShapesCommand* cmd = FW_NEW(CGroupShapesCommand, (ev, this->GetLastActiveFrame(ev), fDrawSelection));
  708.                 cmd->Execute(ev);
  709.               }
  710.                 break;
  711.             case cUngroup:
  712.               {
  713.                 CUngroupShapesCommand* cmd = FW_NEW(CUngroupShapesCommand, (ev, this->GetLastActiveFrame(ev), fDrawSelection));
  714.                 cmd->Execute(ev);
  715.               }
  716.                 break;
  717.                 
  718.             case cAlignObjects:
  719.             case cAlignToGrid:
  720.             case cRotate:
  721.             case cFlipH:
  722.             case cFlipV:
  723.             case cLock:
  724.             case cUnlock:
  725.             case cScaleSelection:
  726.                 FW_NoteAlert(name, sorry);
  727.                 break;
  728.  
  729.             case cRoundCorners:
  730.                 OpenRoundCornersDialog(ev);
  731.                 break;
  732.  
  733.             case cInchUnit:
  734.             case cCmUnit:
  735.             case cPixelUnit:
  736.             case cPicaUnit:
  737.                 fUnit = commandID;
  738.                 FW_NoteAlert(name, sorry);
  739.                 break;
  740.                 
  741.             case cDegreesUnit:
  742.             case cRadiansUnit:
  743.                 fArcUnit = commandID;
  744.                 FW_NoteAlert(name, sorry);
  745.                 break;
  746.  
  747.             default:
  748.                 result = FW_kNotHandled;
  749.         }    
  750.     }
  751.     
  752.     return result;
  753. }
  754.  
  755. //----------------------------------------------------------------------------------------
  756. // CDrawPart::OpenRoundCornersDialog
  757. //----------------------------------------------------------------------------------------
  758.  
  759. void CDrawPart::OpenRoundCornersDialog(Environment* ev)
  760. {
  761.     FW_CPoint position(FW_kZeroPoint);
  762.     FW_CPoint size(FW_IntToFixed(312), FW_IntToFixed(96));
  763.     FW_WindowStyle style = FW_kStandardDialogPosition | FW_kHasCaption;
  764.  
  765.     FW_CString title;
  766.     FW_PSharedLibraryResourceFile resFile(ev);
  767.     ::FW_LoadStringByID(ev, resFile, kRoundCornersStrings, FW_kMultiStringRes, kRoundCornersTitleString, title);
  768.  
  769.     FW_CDialogFrame::NewAndShowModalDialog(ev, 
  770.                                             this,                        // Your part
  771.                                             fRoundCornersPresentation,     // Used in NewFrame
  772.                                             size,                         // Window size
  773.                                             position,                     // Window position
  774.                                             style,                        // Make dialog moveable
  775.                                             title);                        // Title for moveable dialog
  776. }
  777.  
  778. //----------------------------------------------------------------------------------------
  779. //    CDrawPart::SetTool
  780. //----------------------------------------------------------------------------------------
  781. void CDrawPart::SetTool(Environment* ev, unsigned short newTool)
  782. {
  783.     if (fTool != newTool)
  784.     {
  785.         if (fTool == kSelectTool && !fDrawSelection->IsEmpty(ev))
  786.             fDrawSelection->CloseSelection(ev);
  787.         
  788.         CheckTool(ev, fTool, newTool);
  789.         fTool = newTool;        
  790.     }
  791. }
  792.  
  793. //----------------------------------------------------------------------------------------
  794. //    CDrawPart::SetRenderVerb
  795. //----------------------------------------------------------------------------------------
  796.  
  797. void CDrawPart::SetRenderVerb(Environment* ev, unsigned short renderVerb)
  798. {
  799.     if (fRenderVerb != renderVerb)
  800.     {        
  801.         if (!fDrawSelection->IsEmpty(ev))
  802.         {
  803.             CChangeRenderVerbCommand* cmd = FW_NEW(CChangeRenderVerbCommand,
  804.                                                     (ev, this, this->GetLastActiveFrame(ev), fDrawSelection, renderVerb));
  805.             cmd->Execute(ev);
  806.         }
  807.  
  808.         unsigned short oldRenderVerb = fRenderVerb;
  809.         fRenderVerb = renderVerb;        
  810.         CheckRenderVerb(ev, oldRenderVerb, fRenderVerb);
  811.     }
  812. }
  813.  
  814. //----------------------------------------------------------------------------------------
  815. //    CDrawPart::NewFrame
  816. //----------------------------------------------------------------------------------------
  817.  
  818. FW_CFrame* CDrawPart::NewFrame(Environment* ev, 
  819.                                 ODFrame* odFrame, 
  820.                                 FW_CPresentation* presentation,
  821.                                 FW_Boolean fromStorage)
  822. {
  823. FW_UNUSED(fromStorage);
  824.     if (presentation == fRoundCornersPresentation)
  825.     {
  826.         return FW_NEW(CRoundCornersDialogFrame, (ev, odFrame, presentation, this));
  827.     }
  828.     else if (presentation == fPalettePresentation)
  829.     {
  830.         if (fPaletteFrame)
  831.             return fPaletteFrame;
  832.         else
  833.         {
  834.             fPaletteFrame = FW_NEW(CPaletteFrame, (ev, odFrame, presentation, this));
  835.             
  836.             CColorChangedInterest interest(fPaletteFrame);
  837.             AddInterest(interest);            
  838.                 
  839.             return fPaletteFrame;
  840.         }
  841.     }
  842.     else if (presentation == fPatternPresentation)
  843.     {
  844.         if (fPatternFrame)
  845.             return fPatternFrame;
  846.         else
  847.         {
  848.             fPatternFrame = FW_NEW(CPatternFrame, (ev, odFrame, presentation, this));
  849.             
  850.             CPatternChangedInterest interest(fPatternFrame);
  851.             AddInterest(interest);
  852.                         
  853.             return fPatternFrame;
  854.         }
  855.     }
  856.     else if (presentation == fToolPresentation)
  857.     {
  858.         if (fToolFrame)
  859.             return fToolFrame;
  860.         else
  861.         {
  862.             fToolFrame = FW_NEW(CToolFrame, (ev, odFrame, presentation, this));
  863.             
  864.             CColorChangedInterest colorInterest(this);
  865.             fToolFrame->AddInterest(colorInterest);
  866.             CPatternChangedInterest patternInterest(this);
  867.             fToolFrame->AddInterest(patternInterest);
  868.  
  869.             return fToolFrame;
  870.         }
  871.     }
  872.     
  873.     return FW_NEW(CDrawFrame, (ev, odFrame, presentation, this));
  874. }
  875.  
  876. //----------------------------------------------------------------------------------------
  877. //    CDrawPart::DoAdjustMenus
  878. //----------------------------------------------------------------------------------------
  879.  
  880. FW_Handled CDrawPart::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar, FW_Boolean hasMenuFocus, FW_Boolean isRoot)
  881. {
  882. FW_UNUSED(isRoot);
  883.     if (!hasMenuFocus)
  884.         return FW_kNotHandled;
  885.         
  886.     // ----- If active frame not a main frame simply exit
  887.     FW_CFrame* activeFrame = GetLastActiveFrame(ev);
  888.     if ((activeFrame == NULL) || (activeFrame->GetPresentation(ev) != fMainPresentation))
  889.         return FW_kNotHandled;
  890.  
  891.     ODCommandID command;
  892.     FW_Boolean hasSelection = fDrawSelection->Count() > 0;
  893.     FW_Boolean oneShapeSelected = fDrawSelection->Count() == 1;
  894.     
  895.     // ----- Edit Menu -----
  896.     menuBar->EnableCommand(ev, kODCommandSelectAll, fPartContent->CountShapes() > 0);
  897.  
  898.     // ----- PenSize Menu -----
  899.     FW_Fixed penSize = fCurrentPenSize;
  900.     if (fDrawSelection->Count() >= 1)
  901.     {
  902.         if (!fDrawSelection->GetSelectionPenSize(ev, penSize))
  903.         {
  904.             penSize = FW_kFixed0;
  905.         }
  906.     }
  907.     command = FW_FixedToInt(penSize) + cPen1 - 1;
  908.  
  909.     for (ODCommandID p = cPen1; p <= cPen5; p++)
  910.         menuBar->EnableAndCheckCommand(ev, p, TRUE, p == command);
  911.     
  912.     FW_Boolean readWrite = !IsReadOnly(ev);
  913.     
  914.     // ----- Arrange Menu -----
  915.     menuBar->EnableCommand(ev, cMoveForward, readWrite && hasSelection);
  916.     menuBar->EnableCommand(ev, cMoveToFront, readWrite && hasSelection);
  917.     menuBar->EnableCommand(ev, cMoveBackward, readWrite && hasSelection);
  918.     menuBar->EnableCommand(ev, cMoveToBack, readWrite && hasSelection);
  919.     menuBar->EnableCommand(ev, cAlignToGrid, readWrite && hasSelection);
  920.     menuBar->EnableCommand(ev, cAlignObjects, readWrite && hasSelection);
  921.     menuBar->EnableCommand(ev, cRotate, readWrite && hasSelection);
  922.     menuBar->EnableCommand(ev, cFlipH, readWrite && hasSelection);
  923.     menuBar->EnableCommand(ev, cFlipV, readWrite && hasSelection);
  924.     menuBar->EnableCommand(ev, cGroup, readWrite && hasSelection && !oneShapeSelected);
  925.     menuBar->EnableCommand(ev, cUngroup, readWrite && hasSelection);
  926.     menuBar->EnableCommand(ev, cLock, readWrite && hasSelection);
  927.     menuBar->EnableCommand(ev, cUnlock, readWrite && hasSelection);
  928.         
  929.     // ----- Options Menu -----
  930.     menuBar->EnableAndToggleCommand(ev, cAutoGrid, TRUE, !fAutoGrid);
  931.     menuBar->EnableCommand(ev, cScaleSelection, readWrite && hasSelection);
  932.  
  933.     // Enable the Round Corners command only if the dialog is not already active 
  934.     menuBar->EnableCommand(ev, cRoundCorners, activeFrame->GetPresentation(ev) != fRoundCornersPresentation);
  935.  
  936.     // ----- Units Menu -----
  937.     menuBar->EnableAndCheckCommand(ev, cInchUnit, TRUE, fUnit == cInchUnit);
  938.     menuBar->EnableAndCheckCommand(ev, cCmUnit, TRUE, fUnit == cCmUnit);
  939.     menuBar->EnableAndCheckCommand(ev, cPixelUnit, TRUE, fUnit == cPixelUnit);
  940.     menuBar->EnableAndCheckCommand(ev, cPicaUnit, TRUE, fUnit == cPicaUnit);
  941.     menuBar->EnableAndCheckCommand(ev, cDegreesUnit, TRUE, fArcUnit == cDegreesUnit);
  942.     menuBar->EnableAndCheckCommand(ev, cRadiansUnit, TRUE, fArcUnit == cRadiansUnit);
  943.  
  944.     // ----- Window Menu -----
  945.     menuBar->EnableAndToggleCommand(ev, cHideShowTools, TRUE, fToolsWindow == NULL || !fToolsWindow->IsShown(ev));
  946.     menuBar->EnableAndToggleCommand(ev, cHideShowPalette, TRUE, fPaletteWindow == NULL || !fPaletteWindow->IsShown(ev));
  947.     menuBar->EnableAndToggleCommand(ev, cHideShowPattern, TRUE, fPatternWindow == NULL || !fPatternWindow->IsShown(ev));    
  948.     
  949.     return FW_kNotHandled;
  950. }
  951.  
  952. //----------------------------------------------------------------------------------------
  953. //    CDrawPart::CheckTool
  954. //----------------------------------------------------------------------------------------
  955.  
  956. void CDrawPart::CheckTool(Environment* ev, unsigned short oldTool, unsigned short newTool)
  957. {
  958.     if (fToolFrame != NULL)
  959.         fToolFrame->CheckTool(ev, oldTool, newTool);
  960. }
  961.  
  962. //----------------------------------------------------------------------------------------
  963. //    CDrawPart::CheckRenderVerb
  964. //----------------------------------------------------------------------------------------
  965.  
  966. void CDrawPart::CheckRenderVerb(Environment* ev, unsigned short oldRenderVerb, unsigned short newRenderVerb)
  967. {
  968.     if (fToolFrame != NULL)
  969.         fToolFrame->CheckRenderVerb(ev, oldRenderVerb, newRenderVerb);
  970. }
  971.  
  972. //----------------------------------------------------------------------------------------
  973. //    CDrawPart::UpdateAfterMove
  974. //----------------------------------------------------------------------------------------
  975.  
  976. void CDrawPart::UpdateAfterMove(Environment* ev)
  977. {
  978.     CDrawFacetClipper facetClipper(this);
  979.     facetClipper.Clip(ev, fMainPresentation, fDrawSelection->GetUpdateShape());
  980.     
  981.     fMainPresentation->Invalidate(ev, fDrawSelection->GetUpdateShape());    
  982. }
  983.  
  984. //----------------------------------------------------------------------------------------
  985. //    CDrawPart::NotifyForColorChanged
  986. //----------------------------------------------------------------------------------------
  987.  
  988. void CDrawPart::NotifyForColorChanged(Environment *ev, const FW_CColor& color, FW_ERenderVerbs renderVerb)
  989. {
  990.     CColorChangedInterest interest(this);
  991.     CColorChangedNotification notification(interest, color, renderVerb);
  992.     Notify(ev, notification);
  993. }
  994.  
  995. //----------------------------------------------------------------------------------------
  996. //    CDrawPart::NotifyForPatternChanged
  997. //----------------------------------------------------------------------------------------
  998.  
  999. void CDrawPart::NotifyForPatternChanged(Environment *ev, short patIndex, FW_ERenderVerbs renderVerb)
  1000. {
  1001.     CPatternChangedInterest interest(this);
  1002.     CPatternChangedNotification notification(interest, patIndex, renderVerb);
  1003.     Notify(ev, notification);
  1004. }
  1005.  
  1006. //----------------------------------------------------------------------------------------
  1007. //    CDrawPart::SetColor
  1008. //----------------------------------------------------------------------------------------
  1009.  
  1010. void CDrawPart::SetColor(Environment *ev, const FW_CColor& color, FW_ERenderVerbs renderVerb)
  1011. {
  1012.     if (fDrawSelection->IsEmpty(ev))
  1013.     {
  1014.         if (renderVerb == FW_kFrame)
  1015.             fFrameColor = color;
  1016.         else
  1017.             fFillColor = color;
  1018.         NotifyForColorChanged(ev, color, renderVerb);
  1019.     }
  1020.     else
  1021.     {
  1022.         CChangeColorCommand* cmd = FW_NEW(CChangeColorCommand,
  1023.                                             (ev, (renderVerb == FW_kFrame ? cChangeFrameColor: cChangeFillColor), this, this->GetLastActiveFrame(ev), fDrawSelection, color));
  1024.         cmd->Execute(ev);
  1025.     }
  1026. }
  1027.  
  1028. //----------------------------------------------------------------------------------------
  1029. //    CDrawPart::SetPattern
  1030. //----------------------------------------------------------------------------------------
  1031.  
  1032. void CDrawPart::SetPattern(Environment *ev, short newFillPatIndex, FW_ERenderVerbs renderVerb)
  1033. {
  1034.     if (fDrawSelection->IsEmpty(ev))
  1035.     {
  1036.         if (renderVerb == FW_kFrame)
  1037.             fFramePatIndex = newFillPatIndex;
  1038.         else
  1039.             fFillPatIndex = newFillPatIndex;
  1040.         NotifyForPatternChanged(ev, newFillPatIndex, renderVerb);
  1041.     }
  1042.     else
  1043.     {
  1044.         FW_CPattern pattern = GetPattern(newFillPatIndex).Copy();
  1045.         CChangePatternCommand* cmd = FW_NEW(CChangePatternCommand,
  1046.                                                 (ev, (renderVerb == FW_kFrame ? cChangeFramePattern : cChangeFillPattern), this, this->GetLastActiveFrame(ev), fDrawSelection, pattern));
  1047.         cmd->Execute(ev);
  1048.     }
  1049. }
  1050.  
  1051. //----------------------------------------------------------------------------------------
  1052. // CDrawPart::WhichShape
  1053. //----------------------------------------------------------------------------------------
  1054.  
  1055. CBaseShape* CDrawPart::WhichShape(Environment *ev, FW_CGraphicContext& gc, const FW_CMouseEvent& theMouseEvent, FW_Boolean hasToBeSelected) const
  1056. {
  1057.     CDrawContentShapeIterator ite(fPartContent);
  1058.     for (CBaseShape* shape = ite.Last(); ite.IsNotComplete(); shape = ite.Previous())
  1059.     {
  1060.         FW_Boolean test = (!hasToBeSelected) || (hasToBeSelected && shape->IsSelectedShape());
  1061.         if (test && shape->HitTest(ev, gc, theMouseEvent))
  1062.             return shape;    
  1063.     }
  1064.     
  1065.     return NULL;
  1066. }
  1067.  
  1068. //----------------------------------------------------------------------------------------
  1069. // CDrawPart::FindShapeWithIndex
  1070. //----------------------------------------------------------------------------------------
  1071. CBaseShape* CDrawPart::FindShapeWithIndex(short extIndex)
  1072. {
  1073.     // Search the shape list and return the shape with the specified externalization index
  1074.     CDrawContentShapeIterator ite(fPartContent);
  1075.     for (CBaseShape* shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
  1076.     {
  1077.         if (shape->GetExternalizationIndex() == extIndex)
  1078.             return shape;
  1079.     }    
  1080.  
  1081.     // extIndex not found!?
  1082.     return NULL;
  1083. }
  1084.  
  1085. //----------------------------------------------------------------------------------------
  1086. // CDrawPart::DoPostCreate
  1087. //----------------------------------------------------------------------------------------
  1088. void CDrawPart::DoPostCreate(Environment* ev)
  1089. {
  1090.     // Perform "DoPostCreate"-type initialization.
  1091.     // In our case, we want to make sure that any subscribers that were just internalized 
  1092.     // get registered for automatic updates.
  1093.  
  1094.     if (!fPostCreated)    // do this only once!
  1095.     {
  1096.         CDrawLinkManager* linkMgr = (CDrawLinkManager*) this->GetLinkManager(ev);
  1097.         linkMgr->RegisterLinks(ev);
  1098.         fPostCreated = TRUE;
  1099.     }
  1100. }
  1101.  
  1102. //----------------------------------------------------------------------------------------
  1103. // CDrawPart::NewElementIterator
  1104. //----------------------------------------------------------------------------------------
  1105.  
  1106. FW_CElementIterator* CDrawPart::NewElementIterator(Environment* ev,
  1107.                                                 FW_CPart* part,
  1108.                                                 ODDescType desiredClass) const
  1109. {
  1110.     FW_CElementIterator* iter;
  1111.     
  1112.     unsigned short shapeType;
  1113.     
  1114.     if (desiredClass == typeWildCard || desiredClass == kShapeClass || ShapeClassToType(desiredClass, shapeType))
  1115.         iter = FW_NEW(CSemanticShapeElementIterator, (fPartContent, desiredClass));
  1116.     else
  1117.         iter = FW_MEmbeddingPartScriptable::NewElementIterator(ev, part, desiredClass);
  1118.         
  1119.     return iter;
  1120. }
  1121.  
  1122. //----------------------------------------------------------------------------------------
  1123. // CDrawPart::DoAECreateElement
  1124. //----------------------------------------------------------------------------------------
  1125.  
  1126. void CDrawPart::DoAECreateElement(Environment* ev,
  1127.                                 FW_CPart* part,
  1128.                                 const FW_CAppleEvent& event,
  1129.                                 FW_CAppleEvent& reply)
  1130. {
  1131.     ODDescType         shapeClass = event.GetType(keyAEObjectClass);
  1132.     unsigned short     shapeType;
  1133.     
  1134.     if (ShapeClassToType(shapeClass, shapeType))
  1135.     {
  1136.         CBaseShape* theShape = GetDrawContent()->NewShape(ev, shapeType);
  1137.         FW_CColor color;
  1138.     
  1139.         theShape->SetFrameInk(FW_kNormalInk);
  1140.         theShape->SetFrameStyle(FW_kNormalStyle);
  1141.     
  1142.         theShape->ChangeRenderVerb(ev, GetRenderVerb());
  1143.         theShape->ChangePenSize(ev, GetPenSize());
  1144.             
  1145.         GetFrameColor(color);
  1146.         theShape->ChangeFrameColor(ev, color);
  1147.  
  1148.         GetFillColor(color);
  1149.         theShape->ChangeFillColor(ev, color);
  1150.     
  1151.         theShape->ChangeFramePattern(ev, GetFramePattern());
  1152.         theShape->ChangeFillPattern(ev, GetFillPattern());
  1153.     
  1154.         FW_CPoint topLeft(FW_IntToFixed(10), FW_IntToFixed(10));
  1155.         FW_CPoint botRight(FW_IntToFixed(82), FW_IntToFixed(82));
  1156.     
  1157.         theShape->SetShapeGeometry(topLeft, botRight);
  1158.         
  1159.         if (event.HasDataKey(keyAEPropData))
  1160.         {
  1161.             FW_CDesc properties;
  1162.             event.GetDataByDesc(properties, keyAEPropData, typeAERecord);
  1163.             theShape->SetProperties(ev, part, properties);
  1164.         }
  1165.         
  1166.         CDrawShapeCommand* cmd = FW_NEW(CDrawShapeCommand,
  1167.                     (ev, this, FW_MScriptable::GetFrame(ev, part), fDrawSelection, theShape));
  1168.     
  1169.         theShape->Release();
  1170.         
  1171.         cmd->Execute(ev);
  1172.     
  1173.         GetDrawContent()->RedrawShape(ev, theShape);
  1174.     
  1175.         FW_CDesc objectSpec;
  1176.     
  1177.         BuildObjectSpecifier(ev, part, FW_MScriptable::GetFrame(ev, part), objectSpec, GetSpecifierForm());
  1178.         reply.PutDataByDesc(objectSpec, keyAEResult);
  1179.     }
  1180.     else
  1181.         FW_MEmbeddingPartScriptable::DoAECreateElement(ev, part, event, reply);
  1182. }
  1183.  
  1184. //----------------------------------------------------------------------------------------
  1185. // CDrawPart::ShapeClassToType
  1186. //----------------------------------------------------------------------------------------
  1187.  
  1188. FW_Boolean CDrawPart::ShapeClassToType(ODDescType shapeClass,
  1189.                                     unsigned short& shapeType) const
  1190. {
  1191.     FW_Boolean result = TRUE;
  1192.     
  1193.     switch(shapeClass)
  1194.     {
  1195.         case cLine:
  1196.             shapeType = kLineShape;
  1197.             break;
  1198.         
  1199.         case cRectangle:
  1200.             shapeType = kRectShape;
  1201.             break;
  1202.         
  1203.         case cOval:
  1204.             shapeType = kOvalShape;
  1205.             break;
  1206.         
  1207.         case cRoundedRectangle:
  1208.             shapeType = kRRectShape;
  1209.             break;
  1210.             
  1211.         case cText:
  1212.             shapeType = kTextShape;
  1213.             break;
  1214.         
  1215.         default:
  1216.             result = FALSE;
  1217.             break;
  1218.     }
  1219.     
  1220.     return result;
  1221. }
  1222.  
  1223.  
  1224. //----------------------------------------------------------------------------------------
  1225. // CDrawPart::EmbeddedFrameRemoved
  1226. //----------------------------------------------------------------------------------------
  1227.  
  1228. void CDrawPart::EmbeddedFrameRemoved(Environment *ev, FW_MProxy* proxy)
  1229. {
  1230.     CProxyShape* proxyShape = (CProxyShape*)proxy;
  1231.     
  1232.     FW_CRect updateBox;
  1233.     proxyShape->GetUpdateBox(updateBox);
  1234.     
  1235.     fMainPresentation->Invalidate(ev, updateBox);
  1236.     
  1237.     // ----- I don't need to call RemoveShapeFromPart because the embedded frames have already been
  1238.     // ----- deleted (ODF calls FW_MProxy::RemoveEmbeddedFrames)
  1239.     fPartContent->RemoveShape(ev, proxyShape);
  1240. }
  1241.  
  1242. //----------------------------------------------------------------------------------------
  1243. // CDrawPart::HandleNotification
  1244. //----------------------------------------------------------------------------------------
  1245.  
  1246. void CDrawPart::HandleNotification(Environment* ev, const FW_CNotification& notification)
  1247. {
  1248.     switch (notification.GetMessage()) {
  1249.         case kColorChanged:    
  1250.             {
  1251.                 CColorChangedNotification& colorNotification = (CColorChangedNotification&)notification;
  1252.                 SetColor(ev, colorNotification.GetColor(), colorNotification.GetRenderVerb());
  1253.             }
  1254.             break;
  1255.         case kPatternChanged:    
  1256.             {
  1257.                 CPatternChangedNotification& patternNotification = (CPatternChangedNotification&)notification;
  1258.                 SetPattern(ev, patternNotification.GetPattern(), patternNotification.GetRenderVerb());
  1259.             }
  1260.             break;
  1261.     };
  1262. }
  1263.     
  1264. //========================================================================================
  1265. // Custom Edit Menu stuff
  1266. //========================================================================================
  1267.  
  1268. //----------------------------------------------------------------------------------------
  1269. // CDrawPart::FocusAcquiredInFrame
  1270. //----------------------------------------------------------------------------------------
  1271. void CDrawPart::FocusAcquiredInFrame(Environment* ev, ODTypeToken focus, FW_CFrame* frame)
  1272. {
  1273.     FW_CPart::FocusAcquiredInFrame(ev, focus, frame);    // call inherited
  1274.  
  1275.     if (focus == FW_CPart::fgSelectionFocusToken)
  1276.     {
  1277.         static short done = false;
  1278.         
  1279.         if (!done && frame->IsRoot(ev) && !fToolsWindow->IsShown(ev))
  1280.         {
  1281.             done = TRUE;
  1282.             fToolsWindow->ShowHide(ev, TRUE);
  1283.         }
  1284.     }
  1285.     else if ((focus == FW_CPart::fgMenuFocusToken) && !fHasMenuFocus)
  1286.     {
  1287.         // The part is acquiring the menu focus
  1288.         InstallCustomEditMenu(ev);
  1289.         fHasMenuFocus = true;
  1290.     }
  1291. }
  1292.  
  1293. //----------------------------------------------------------------------------------------
  1294. // CDrawPart::FocusLostInFrame
  1295. //----------------------------------------------------------------------------------------
  1296. void CDrawPart::FocusLostInFrame(Environment* ev, ODTypeToken focus, FW_CFrame* frame,   
  1297.                                  FW_Boolean samePart)
  1298. {
  1299.     FW_CPart::FocusLostInFrame(ev, focus, frame, samePart);    // call inherited
  1300.     // samePart is true if the focus is passing to another frame in this part
  1301.  
  1302.     if ((focus == FW_CPart::fgMenuFocusToken) && !samePart && fHasMenuFocus)
  1303.     {
  1304.         // The part is losing the menu focus
  1305.         UninstallCustomEditMenu(ev);
  1306.         fHasMenuFocus = false;
  1307.     }
  1308. }
  1309.  
  1310. //----------------------------------------------------------------------------------------
  1311. // CDrawPart::InstallCustomEditMenu
  1312. //----------------------------------------------------------------------------------------
  1313. // This function should be called whenever the part gets the menu focus.
  1314.  
  1315. void CDrawPart::InstallCustomEditMenu(Environment* ev)
  1316. {
  1317.     // Install a "Duplicate" menu item in the Edit menu before Select All
  1318.     FW_CMenuBar* menuBar = GetMenuBar(ev);
  1319.     FW_CAcquiredODMenuBar aqODMenuBar = menuBar->AcquireODMenuBar(ev);
  1320.     short menuID;
  1321.     short itemID;
  1322.  
  1323.     // Find out where the kODCommandSelectAll item is
  1324.     aqODMenuBar->GetMenuAndItem(ev, kODCommandSelectAll, &menuID, &itemID);
  1325.     fEditMenuID = menuID;
  1326.     fEditMenuPosition = itemID;
  1327.  
  1328.     // Unregister kODCommandSelectAll etc.
  1329.     aqODMenuBar->UnregisterCommand(ev, kODCommandSelectAll);
  1330.     aqODMenuBar->UnregisterCommand(ev, kODCommandGetPartInfo);
  1331.     aqODMenuBar->UnregisterCommand(ev, kODCommandPreferences);
  1332.     aqODMenuBar->UnregisterCommand(ev, kODCommandViewAsWin);
  1333.  
  1334.     // Get the string for the new menu item
  1335.     FW_PSharedLibraryResourceFile resFile(ev);
  1336.     FW_CString string;
  1337.     Str255 str;
  1338.     ::FW_LoadStringByID(ev, resFile, kDrawStrings, FW_kMultiStringRes, kDuplicateString, string);
  1339.     string.ExportPascal(str);
  1340.  
  1341.     // Insert the item and register its command
  1342.     ODPlatformMenu platformMenu = aqODMenuBar->GetMenu(ev, menuID);
  1343.     ::InsertMenuItem(platformMenu, str, itemID-1); // insert before Select All item
  1344.     aqODMenuBar->RegisterCommand(ev, cDuplicate, menuID, itemID);
  1345.  
  1346.     // Re-register kODCommandSelectAll etc. at their original positions + 1
  1347.     aqODMenuBar->RegisterCommand(ev, kODCommandSelectAll, menuID, itemID+1);
  1348.     aqODMenuBar->RegisterCommand(ev, kODCommandGetPartInfo, menuID, itemID+3);
  1349.     aqODMenuBar->RegisterCommand(ev, kODCommandPreferences, menuID, itemID+4);
  1350.     aqODMenuBar->RegisterCommand(ev, kODCommandViewAsWin, menuID, itemID+6);
  1351. }
  1352.  
  1353. //----------------------------------------------------------------------------------------
  1354. // CDrawPart::UninstallCustomEditMenu
  1355. //----------------------------------------------------------------------------------------
  1356. // This function should be called whenever the part loses the menu focus.
  1357.  
  1358. void CDrawPart::UninstallCustomEditMenu(Environment* ev)
  1359. {
  1360.     // Remove the "Duplicate" menu item
  1361.     FW_CMenuBar* menuBar = GetMenuBar(ev);
  1362.     FW_CAcquiredODMenuBar aqODMenuBar = menuBar->AcquireODMenuBar(ev);
  1363.  
  1364.     //-- Unregister cDuplicate and all the commands that follow it in the Edit menu
  1365.     aqODMenuBar->UnregisterCommand(ev, cDuplicate);
  1366.     aqODMenuBar->UnregisterCommand(ev, kODCommandSelectAll);
  1367.     aqODMenuBar->UnregisterCommand(ev, kODCommandGetPartInfo);
  1368.     aqODMenuBar->UnregisterCommand(ev, kODCommandPreferences);
  1369.     aqODMenuBar->UnregisterCommand(ev, kODCommandViewAsWin);
  1370.  
  1371.     //-- Remove our item
  1372.     ODPlatformMenu platformMenu = aqODMenuBar->GetMenu(ev, fEditMenuID);
  1373.     ::DeleteMenuItem(platformMenu, fEditMenuPosition);
  1374.  
  1375.     //-- Re-register kODCommandSelectAll etc. at their original positions
  1376.     aqODMenuBar->RegisterCommand(ev, kODCommandSelectAll, fEditMenuID, fEditMenuPosition);
  1377.     aqODMenuBar->RegisterCommand(ev, kODCommandGetPartInfo, fEditMenuID, fEditMenuPosition+2);
  1378.     aqODMenuBar->RegisterCommand(ev, kODCommandPreferences, fEditMenuID, fEditMenuPosition+3);
  1379.     aqODMenuBar->RegisterCommand(ev, kODCommandViewAsWin, fEditMenuID, fEditMenuPosition+5);
  1380. }
  1381.